package com.shoukaiseki.test.spring.springsession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * <br>
 *
 * @author 蒋カイセキ    Japan-Tokyo  18-10-24 上午10:38<br>
 * ブログ http://www.shoukaiseki.top/<br>
 * E-メール jiang28555@Gmail.com<br>
 **/
@Controller
public class HelloController {


    @RequestMapping("/")
    @ResponseBody
    public String index(HttpSession session){
        long l = System.currentTimeMillis();
        String username = "asus" + l;
        session.setAttribute("username", username);
        return "hello: this.username="+username+"<br><a href='get' target='_blank'>查看session</a>";
    }


    @RequestMapping("/get")
    @ResponseBody
    public String get(HttpSession session){
        Object admin = session.getAttribute("username");
        return admin==null?"null":admin.toString();
    }
}
